<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>更新个人信息</title>
    <link rel="stylesheet" href="/layuimoduls/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimoduls/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
            修改个人信息
        </blockquote>

        <form class="layui-form" lay-filter="form" id="form">
            <div class="layui-form-item">
                <label class="layui-form-label">您的真实姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="realname"  class="layui-input" th:value="${studentinfo.realname}" disabled>
                </div>
                <div class="layui-form-mid layui-word-aux" >账号注册成功，真实性姓名无法修改哦</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">登录名</label>
                <div class="layui-input-inline">
                    <input type="text" name="username"  class="layui-input" th:value="${studentinfo.username}">
                </div>
                <div class="layui-form-mid layui-word-aux" ></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">学生ID</label>
                <div class="layui-input-inline">
                    <input type="text" name="studentid"  class="layui-input" th:value="${studentinfo.studentid}" disabled>
                </div>
                <div class="layui-form-mid layui-word-aux" >学生id暂时不可更改哦</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">修改密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="pwd" name="password" placeholder="请输入原密码"  class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux" >
                    <i class="layui-icon" style="font-size: 30px; color: #72D8A5; display:none" id="tip">&#xe605;</i>
                    <i class="layui-icon" style="font-size: 30px; color: orangered; display:none" id="tip2">&#x1006;</i>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password2" placeholder="请输入新密码"  class="layui-input" id="pwd2">
                </div>
                <div class="layui-form-mid layui-word-aux" id="msg">请填写6到12位密码</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">您的电话</label>
                <div class="layui-input-inline">
                    <input type="text" name="serialnumber"  class="layui-input" th:value="${studentinfo.serialnumber}">
                </div>
                <div class="layui-form-mid layui-word-aux" ></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">您的邮箱</label>
                <div class="layui-input-inline">
                    <input type="text" name="mailnumber"  class="layui-input" th:value="${studentinfo.mailnumber}" >
                </div>
                <div class="layui-form-mid layui-word-aux" ></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">您的学院</label>
                <div class="layui-input-inline">
                    <input type="text" name="college"  class="layui-input" th:value="${studentinfo.college}" >
                </div>
                <div class="layui-form-mid layui-word-aux" ></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">科目选择</label>
                <div class="layui-input-block">
                    <label>
                        <input type="checkbox" th:each="subtea:${subteas}"  th:title="${subtea}"
                               th:checked="${subjectinfo.contains(subtea)}" th:value="${subtea}">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-disabled"  lay-submit="" lay-filter="modifystudentinfo" id="send" readonly="readonly">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>


    </div>
</div>
<script src="/layuimoduls/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/jquery/jquery-3.6.0.js"></script>
<script  th:inline="none">
    var flag = false;
    var flag2 =false;
    layui.use(['form','layer'], function () {
        var form = layui.form

        form.render();
        $('#form').click(function (e) {
            //禁用表单的默认提交事件
            e.preventDefault();
        })
        function isEmpty(obj) {  if (typeof obj === 'undefined' || obj == null || obj === '') {    return true;  } else {    return false;  }}
        $("#pwd").blur(function(){
            $.ajax({
                url:'/pwdVerify2',
                data:JSON.stringify({username:$('input[name=username]').val(),
                    password:$('input[name=password]').val()}
                ),
                type:'post',
                contentType:'application/json;charset=utf-8',
                dataType:'json',
                success:function (response) {
                    if(response.success){
                        $("#tip").show();
                        $("#tip2").hide();
                        flag = true;
                    }else{
                        $("#tip").hide();
                        $('#tip2').show();
                        flag = false
                    }
                    if(flag && flag2){
                        $('#send').removeClass("layui-btn-disabled").attr("disabled",false);
                    }else{
                        $('#send').addClass("layui-btn-disabled").attr("disabled",true);
                    }
                }
            })
        })
        $("#pwd2").blur(function(){
            var pwd2 = $('input[name=password2]').val();
            console.log(pwd2.length)
            if( isEmpty(pwd2) || pwd2.length<6){
                layer.alert("新密码不符合规则，请重新输入")
                flag2=false
            }else{
                flag2=true
            }
            if(flag && flag2){
                $('#send').removeClass("layui-btn-disabled").attr("disabled",false);
            }else{
                $('#send').addClass("layui-btn-disabled").attr("disabled",true);
            }
        })
        form.on('submit(modifystudentinfo)', function (data) {
            layer.alert("确定提交？");
            var arr = [];
            $('input[type=checkbox]:checked').each(function() {
                arr.push($(this).val());
            });
            var data = data.field
            data.subjects = arr
            console.log(JSON.stringify(data))
            $.ajax({
                url:'/updateStudentInfo',
                data:JSON.stringify(data),
                type:'post',
                contentType:'application/json;charset=utf-8',
                dataType:'json',
                success:function (response) {
                    if(response.success){
                        layer.msg(response.msg)
                        return false;
                    }else{
                        layer.msg(response.msg)
                        return false;
                    }
                }
            })
        });
    })


</script>
</body>
</html>